<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 
    定时器：
   -->
  <button class="clear_btn">清除定时器</button>
  <button class="start_btn">解除定时器</button>
  <script src="../../js/ultis.js"></script>
  <script>
    //需求:改变body的背景颜色 一秒过后就跟换一个颜色

    let clear_btn = document.querySelector(".clear_btn")
    let start_btn = document.querySelector(".start_btn")
    document.body.style.background = "red"

    let timer = setInterval(() => {
      let color = randomColor()
      document.body.style.background = "#" + color
    }, 1000)
    //清除定时器
    clear_btn.onclick = function () {
      clearInterval(timer)
    }
    //解除定时器
    start_btn.onclick = function () {
      setInterval(() => {
        let color = randomColor()
        document.body.style.background = "#" + color
      }, 1000)
    }
  </script>
</body>

</html>